package com.audaque.springboot.foshanupload.web.streamdemo.dynamice.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.config.BindingProperties;
import org.springframework.cloud.stream.config.BindingServiceProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Supplier;

@Configuration
@Slf4j
public class ProducerConsumerBeanConfig {
    @Autowired(required = false)
    private BindingServiceProperties bindingServiceProperties;

    /**
     * 一个 Consumer< String > myTopic 的方法，Stream 会将其 拆分成 In 和 out 两个通道：
     *
     * 输入 - <functionName> + -in- + < index >
     * myTopic-in-0
     * 输出和主题 - <functionName> + -out- + < index >
     * myTopic-out-0
     * 在rocketmq 管理平台的主题页面搜myTopic即可搜出myTopic-out-0
     */
    @Bean
    public Consumer<Message<String>> myTopic(){
        return (data)->{
            String str = data.getPayload();
            MessageHeaders headers = data.getHeaders();
            System.out.println("myTopic 接收一条记录：" + str);
            System.out.println("getHeaders headerFor：" + headers.get("for"));
        };
    }


}
